/**
 * 快3的规则(基类)
 */
var kuai3Rule = function() {
    this.map = {

    };

    for (var i = 1; i <= 6; i++) {
        this.map['军' + i] = {
            display: '三军 - ' + i,
            rate: 2,
        }
    }
    this.map['大'] = {
        display: '大',
        rate: 1.99,
    }
    this.map['小'] = {
        display: '小',
        rate: 1.99,
    }

    for (var i = 1; i <= 6; i++) {
        this.map['围' + i] = {
            display: '围骰 - ' + i,
            rate: 165,
        }
    }
    this.map['豹'] = {
        display: '全骰',
        rate: 26,
    }

    var arr = [58, 21, 18, 12.5, 9, 7, 7, 7, 7, 9, 12.5, 18, 21, 58];
    for (var i = 4; i <= 17; i++) {
        this.map['点' + i] = {
            display: '点数 - ' + i,
            rate: arr[i - 4],
        }
    }

    // 长牌
    for (var i = 1; i <= 5; i++) {
        for (var j = i + 1; j <= 6; j++) {
            this.map['长' + i + "" + j] = {
                display: '长牌 - ' + i + "" + j,
                rate: 6,
            }
        }
    }

    // 短牌
    for (var i = 1; i <= 6; i++) {
        this.map['短' + i] = {
            display: '短牌 - ' + i,
            rate: 11,
        }
    }
};
kuai3Rule.prototype = {};

kuai3Rule.prototype.isHeBig = function(list) {
    var h = this.he(list);
    return h > 10;
}

// 计算总和
kuai3Rule.prototype.he = function(list) {
    var total = 0;
    for (var i in list) {
        total += parseInt(list[i]);
    }
    return total;
}

kuai3Rule.prototype.isBaoZi = function(list) {
    return list[0] == list[1] && list[0] == list[2];
}

/**
 * 计算长龙信息
 */
kuai3Rule.prototype.long = function(list) {
    var self = this;
    var r = [];
    if (isEmpty(list)) return r;

    // 总和: 大、小
    var l0 = list[0].red;

    var f = function(k, cb) {
        var t = 1;
        for (var i = 1; i < list.length; i++) {
            var l = list[i].red;
            if (!cb(l)) break;
            t++;
        }
        var oo = {}; oo[k] = t;
        if (t > 2) r.push(oo);
    };

    if (self.isHeBig(l0)) {
        f("总和 - 大", function(l) {
            return self.isHeBig(l);
        });
    }
    else {
        f("总和 - 小", function(l) {
            return !self.isHeBig(l);
        });
    }

    // 排序
    r.sort(function(a, b) {
        var v1, v2;
        for (var k in a) v1 = a[k];
        for (var k in b) v2 = b[k];
        return v2 - v1;
    });
    return r;
}

/**
 * 转换显示的名称
 */
kuai3Rule.prototype.getTargetName = function(name) {
    var arr = name.split(":");
    if (arr.length == 1)
        return this.map[name].display;
    return this.map[arr[0]].display + " &nbsp;<span class='blue' style='font-size:12px;'>" + arr[1] + "</span>";
};
